package com.leetcode.partition4;

/**
 * @author `RKC`
 * @date 2021/11/4 8:50
 */
public class LC367有效的完全平方数 {

    public static boolean isPerfectSquare(int num) {
        if (num == 1) return true;
        int left = 1, right = num >> 1;
        while (left <= right) {
            int mid = (left + right) >>> 1;
            long val = (long) mid * mid;
            if (val > num) {
                right = mid - 1;
            } else if (val < num) {
                left = mid + 1;
            } else {
                System.out.println(mid);
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(Math.sqrt(808201));
        System.out.println(isPerfectSquare(808201));
    }
}
